/**
 * 
 */
package view.impl.ingame;

import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;

import view.impl.PositionOffset;


/**
 * @author Julian
 *
 */
public class StaticImageGameObject implements IGameObject {

	private Image img;
	private int posX, posY;
	private int width, height;
	private double depth;
	
	private float horOff, verOff;
	
	public StaticImageGameObject(String imgSrc, int posX, int posY, int width, int height, double depth) throws SlickException {
		this(new Image(imgSrc), posX, posY, width, height, depth, PositionOffset.TOP_LEFT);
	}
	
	StaticImageGameObject(Image img, int posX, int posY, int width, int height, double depth) throws SlickException {
		this(img, posX, posY, width, height, depth, PositionOffset.TOP_LEFT);
	}
	
	StaticImageGameObject(String imgSrc, int posX, int posY, int width, int height, double depth, PositionOffset offset) throws SlickException {
		this(new Image(imgSrc), posX, posY, width, height, depth, offset);
	}
	
	StaticImageGameObject(Image img, int posX, int posY, int width, int height, double depth, PositionOffset offset) throws SlickException {
		this.img = new Image(img.getResourceReference());
		this.posX = posX;
		this.posY = posY;
		this.width = width;
		this.height = height;
		this.depth = depth;
		horOff = (float) (0.5 * (offset.ordinal() % 3));
		verOff = (float) (0.5 * ((int)offset.ordinal() / 3)); // OBS! Detta �r korrekt!
}
	
	/* (non-Javadoc)
	 * @see client.view.IGameObject#draw()
	 */
	@Override
	public void draw(Graphics g, int windowWidth, int windowHeight) {
		float scaleX = (float)windowWidth / 800f;
		float scaleY = (float)windowHeight / 600f;
		img.draw(posX - horOff * img.getWidth() * scaleX, 
				 posY - verOff * img.getHeight() * scaleY, 
				 width * scaleX, 
				 height * scaleY);
	}

	/* (non-Javadoc)
	 * @see client.view.IGameObject#getDepth()
	 */
	@Override
	public double getDepth() {
		return depth;
	}

	/* (non-Javadoc)
	 * @see java.lang.Comparable#compareTo(java.lang.Object)
	 */
	@Override
	public int compareTo(IGameObject o) {
		return (int) Math.signum((depth - o.getDepth()));
	}

}
